<template>
  <div class="essay-detail-container">
    <el-row
      type="flex"
      justify="center">
      <el-col :span="12">
        <div class="markdown-body">
          <h1>{{ detailData.title }}</h1>
          <p class="grey-font">
            {{ detailData.author }} · {{ detailData.time }}
          </p>
          <article v-html="compiledMarkdown(detailData.content ? detailData.content : '')"/>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  let marked = require('marked');

  marked.setOptions({
    renderer: new marked.Renderer(),
    gfm: true,
    tables: true,
    breaks: true,
    pedantic: false,
    sanitize: false,
    smartLists: true,
    smartypants: false
  });

  export default {
    name: 'Detail',
    async asyncData({app , $axios, query}) {
      let res = await $axios.$get(`https://fireleaves.cn/article/single`, {
        params: {
          id: query.id
        }
      });
      return {
        detailData: res
      }
    },
    methods: {
      compiledMarkdown(mdString) {
        return marked(mdString || '', {
          sanitize: false
        });
      }
    },
    head() {
      return this.$seo(`饥荒攻略-${this.detailData.title}`, this.detailData.content.substring(0,30),"掌上饥荒,饥荒攻略,SW攻略,DST攻略,Hamlet攻略,饥荒资讯");
    }
  }
</script>

<style lang="scss" scoped>
  .essay-detail-container {
    padding: 32px;
  }

  .grey-font {
    color: #666666;
    font-size: 12px;
  }
</style>
